package com.example.fristwork

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import java.util.ArrayList

class ListActivity : AppCompatActivity() {
     private val bookList = ArrayList<Book>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initBooks()
        val layoutManager = StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL)
        val recyclerView = findViewById<RecyclerView>(R.id.recyclerView)
        recyclerView.layoutManager = layoutManager
        val adapter = BookAdapter(bookList)
        recyclerView.adapter = adapter
    }


    private fun initBooks() {
        repeat(2) {
            bookList.add(Book("书", R.drawable.book1))
            bookList.add(Book("书", R.drawable.book2))
            bookList.add(Book("书", R.drawable.book3))
            bookList.add(Book("书", R.drawable.book4))
            bookList.add(Book("书", R.drawable.book5))
            bookList.add(Book("书", R.drawable.book6))
            bookList.add(Book("书", R.drawable.book7))
            bookList.add(Book("书", R.drawable.book8))
            bookList.add(Book("书", R.drawable.book9))
            bookList.add(Book("书", R.drawable.book8))
        }
    }
}